/*
 *  Copyright 2011.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.opu.db.obj.vis.ui.util;

import java.io.File;
import java.util.Locale;

/**
 *  It`s singleton class use {@link #getInstance()} to get instance.
 * <br/>
 * <b> Do not use rest class in construcotr !</b>
 *
 */
public final class ConfigPath {
    private static final ConfigPath instance = new ConfigPath();

    private final String os = System.getProperty("os.name");
    private final String userHome = System.getProperty("user.home");
    private final String language = System.getProperty("user.language");

    /**
     * For UNIX: <i>/tmp/</i>db_vdumper/1/ <br />
     * For Widnows: <i>C:\Windows\temp\</i>db_vdumper/1/
     */
    private final String tmp;

    /**
     * For UNIX: <i>/home/{user}/<b>.</b></i>db_vdumper/1/ <br />
     * For Widnows: "<i>C:\Windows\\users\{user}\</i>db_vdumper/1/
     */
    private final File appConfDir;

    private ConfigPath(){
        String s = System.getProperty("file.separator");

        String app = ResourceHandle.getApplicationName()
                + s + ResourceHandle.getApplicationVersion();
        
        appConfDir = new File(userHome + s + (isWindows()? "": ".") + app);
        tmp = System.getProperty("java.io.tmpdir") + s + app;

    }

    public static ConfigPath getInstance() {
        return instance;
    }


    public boolean isWindows(){
        return os.startsWith("Windows");
    }

    public String getLanguage() {
        return language;
    }

    public Locale getLocale(){
        String _language = this.language;
        if (System.getProperty("locale") != null){
            _language = System.getProperty("locale");
        }
        return new Locale(_language);
    }

    public String getOs() {
        return os;
    }

    public String getTmp() {
        return tmp;
    }

    /**
     * For UNIX: "<i>/tmp/</i>db_vdumper/1/ <br />
     * For Widnows: "<i>C:\Windows\temp\</i>db_vdumper/1/
     */
    public File getTmpDir() {
        return new File (getTmp());
    }

    public String getUserHome() {
        return userHome;
    }

    /**
     * For UNIX: <i>/home/{user}/<b>.</b></i>db_vdumper/1/ <br />
     * For Widnows: "<i>C:\Windows\\users\{user}\</i>db_vdumper/1/
     */
    public File getApplicationConfDir() {
        return appConfDir;
    }

    public File getFrameProp(){
        return new File(appConfDir, "window.conf");
    }

    public File getGUIProp(){
        return new File(appConfDir, "gui.conf");
    }

    public File getLogProp(){
        return new File(appConfDir, "logging.conf");
    }

    public File getConnectionProp(){
        return new File(appConfDir, "connection.conf");
    }
}
